Option Strict On
Option Explicit On

'Copyright (c) 2007-2010, William Severance, Jr., WESNet Designs
'All rights reserved.

'Redistribution and use in source and binary forms, with or without modification, are permitted
'provided that the following conditions are met:

'Redistributions of source code must retain the above copyright notice, this list of conditions
'and the following disclaimer.

'Redistributions in binary form must reproduce the above copyright notice, this list of conditions
'and the following disclaimer in the documentation and/or other materials provided with the distribution.

'Neither the name of William Severance, Jr. or WESNet Designs may be used to endorse or promote
'products derived from this software without specific prior written permission.

'Disclaimer: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
'            OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
'            AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE
'            FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
'            LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
'            INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
'            OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
'            IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'Although I will try to answer questions regarding the installation and use of this software when
'such questions are submitted via e-mail to the below address, no promise of further
'support or enhancement is made nor should be assumed.

'Developer Contact Information:
'     William Severance, Jr.
'     WESNet Designs
'     679 Upper Ridge Road
'     Bridgton, ME 04009
'     Phone: 207-647-9375
'     E-Mail: bill@wesnetdesigns.com
'     Website: www.wesnetdesigns.com

Imports Microsoft.VisualBasic
Imports System.IO
Imports System.Xml.Serialization
Imports DotNetNuke.Entities.Modules

Namespace WESNet.DNN.Modules.EPrayer
  Public Class Defaults
    Public Const EnableModeration As Boolean = False
    Public Const NewUsersAreTrusted As Boolean = False
    Public Const NewUsersViewableDistributions As Integer = 1
    Public Const AnonymousUsersViewableDistributions As Integer = 0
    Public Const NewPostDefaultDistributions As Integer = 1
    Public Const AllowOwnPostEditing As Boolean = True
    Public Const AllowOwnPostDeletion As Boolean = False
    Public Const RequestLifespan As Integer = 0
    Public Const MaxBodyLength As Integer = 100
    Public Const PageSize As Integer = 10
    Public Const EnableSubjectContact As Boolean = True
    Public Const EnableSubjectNotification As Boolean = True
    Public Const EnableNotification As Boolean = True
    Public Const TrackVisits As Boolean = True
    Public Const TrackViews As Boolean = True
    Public Const TrackNewPosts As Boolean = False
    Public Const EnableDNNSearch As Boolean = False
    Public Const UseAdminEmailAsSender As Boolean = True
    Public Shared AdminEmail As String
    Public Const MailStyleName As String = "Default"
    Public Const MailFormat As DotNetNuke.Services.Mail.MailFormat = DotNetNuke.Services.Mail.MailFormat.Html
    Public Const MailSendMethod As MailManager.MailSendMethods = MailManager.MailSendMethods.To
    Public Const EnablePerPortalTemplates As Boolean = True

    Shared Sub New()
      Dim ps As PortalSettings = Entities.Portals.PortalController.GetCurrentPortalSettings()
      If ps Is Nothing OrElse ps.Email Is Nothing Then
        AdminEmail = String.Empty
      Else
        AdminEmail = ps.Email
      End If
    End Sub

  End Class

  <Serializable(), XmlRoot("Configuration")> _
  Public Class Configuration

#Region "Private Members"

    Private _ModuleConfiguration As Entities.Modules.ModuleInfo
    Private _ModulePath As String

    Private _ModuleId As Integer = Null.NullInteger
    Private _TabModuleID As Integer = Null.NullInteger
    Private _TabID As Integer = Null.NullInteger

    Private _settings As Hashtable

    Private _Version As String
    Private _ModuleName As String

    Private _EnableModeration As Boolean
    Private _AllowOwnPostEditing As Boolean
    Private _AllowOwnPostDeletion As Boolean
    Private _RequestLifespan As Integer
    Private _NewUsersAreTrusted As Boolean
    Private _NewUsersViewableDistributions As Integer
    Private _AnonymousUsersViewableDistributions As Integer
    Private _NewPostDefaultDistributions As Integer
    Private _MaxBodyLength As Integer
    Private _PageSize As Integer
    Private _EnableSubjectContact As Boolean
    Private _EnableSubjectNotification As Boolean
    Private _EnableNotification As Boolean
    Private _TrackVisits As Boolean
    Private _TrackViews As Boolean
    Private _TrackNewPosts As Boolean
    Private _EnableDNNSearch As Boolean
    Private _UseAdminEmailAsSender As Boolean
    Private _AdminEmail As String
    Private _MailStyleName As String
    Private _MailFormat As DotNetNuke.Services.Mail.MailFormat
    Private _MailSendMethod As MailManager.MailSendMethods
    Private _EnablePerPortalTemplates As Boolean

    'Status information saved by stored proceedures in ModuleSettings
    Private _Stats As Stats

#End Region

#Region "Public ReadOnly Properties"

    Private ReadOnly Property ModuleId() As Integer
      Get
        Return _ModuleId
      End Get
    End Property

    Private ReadOnly Property TabID() As Integer
      Get
        Return _TabID
      End Get
    End Property

    Private ReadOnly Property TabModuleID() As Integer
      Get
        Return _TabModuleID
      End Get
    End Property

    <XmlIgnore()> _
    Public ReadOnly Property Settings() As Hashtable
      Get
        Return _settings
      End Get
    End Property

    Public ReadOnly Property Version() As String
      Get
        If _Version Is Nothing Then
          If _ModuleConfiguration Is Nothing Then
            If (ModuleId <> Null.NullInteger AndAlso TabID <> Null.NullInteger) Then
              Dim mc As New ModuleController
              _Version = mc.GetModule(ModuleId, TabID).DesktopModule.Version
            Else
              _Version = Consts.Version
            End If
          Else
            _Version = _ModuleConfiguration.DesktopModule.Version
          End If
        End If
        Return _Version
      End Get
    End Property

    <XmlIgnore()> _
    Public ReadOnly Property ModulePath() As String
      Get
        If _ModulePath Is Nothing Then
          Dim ApplicationPath As String = DotNetNuke.Common.ApplicationPath
          Dim ControlSrc As String = _ModuleConfiguration.ModuleControl.ControlSrc
          _ModulePath = Path.GetDirectoryName(ApplicationPath & "/" & ControlSrc).Replace("\", "/") & "/"
        End If
        Return _ModulePath
      End Get
    End Property

    <XmlIgnore()> _
    Public ReadOnly Property LocalSharedResourceFile() As String
      Get
        Return ModulePath & Localization.LocalResourceDirectory & "/" & Localization.LocalSharedResourceFile
      End Get
    End Property

    <XmlIgnore()> _
    Public ReadOnly Property ModuleName() As String
      Get
        If _ModuleName Is Nothing Then
          If _ModuleConfiguration Is Nothing Then
            If (ModuleId <> Null.NullInteger AndAlso TabID <> Null.NullInteger) Then
              Dim mc As New ModuleController
              _ModuleName = mc.GetModule(ModuleId, TabID).DesktopModule.ModuleName
            Else
              _ModuleName = Consts.ModuleName
            End If
          Else
            _ModuleName = _ModuleConfiguration.DesktopModule.ModuleName
          End If
        End If
        Return _ModuleName
      End Get
    End Property

    Public Property EnableModeration() As Boolean
      Get
        Return _EnableModeration
      End Get
      Set(ByVal value As Boolean)
        _EnableModeration = value
      End Set
    End Property

    Public Property NewUsersAreTrusted() As Boolean
      Get
        Return _NewUsersAreTrusted
      End Get
      Set(ByVal value As Boolean)
        _NewUsersAreTrusted = value
      End Set
    End Property

    Public Property NewUsersViewableDistributions() As Integer
      Get
        Return _NewUsersViewableDistributions
      End Get
      Set(ByVal value As Integer)
        _NewUsersViewableDistributions = value
      End Set
    End Property

    Public Property AnonymousUsersViewableDistributions() As Integer
      Get
        Return _AnonymousUsersViewableDistributions
      End Get
      Set(ByVal value As Integer)
        _AnonymousUsersViewableDistributions = value
      End Set
    End Property

    Public Property NewPostDefaultDistributions() As Integer
      Get
        Return _NewPostDefaultDistributions
      End Get
      Set(ByVal value As Integer)
        _NewPostDefaultDistributions = value
      End Set
    End Property

    Public Property AllowOwnPostEditing() As Boolean
      Get
        Return _AllowOwnPostEditing
      End Get
      Set(ByVal value As Boolean)
        _AllowOwnPostEditing = value
      End Set
    End Property

    Public Property AllowOwnPostDeletion() As Boolean
      Get
        Return _AllowOwnPostDeletion
      End Get
      Set(ByVal value As Boolean)
        _AllowOwnPostDeletion = value
      End Set
    End Property

    Public Property RequestLifespan() As Integer
      Get
        Return _RequestLifespan
      End Get
      Set(ByVal value As Integer)
        _RequestLifespan = value
      End Set
    End Property

    Public Property MaxBodyLength() As Integer
      Get
        Return _MaxBodyLength
      End Get
      Set(ByVal value As Integer)
        If value < 50 Or value > 999 Then Throw New ArgumentOutOfRangeException("MaxBodyLength", "Must be integer between 50 and 9999")
        _MaxBodyLength = value
      End Set
    End Property

    Public Property PageSize() As Integer
      Get
        Return _PageSize
      End Get
      Set(ByVal value As Integer)
        If value < 0 Or value > 999 Then Throw New ArgumentOutOfRangeException("PageSize", "Must be integer between 0 (no paging) and 999")
        _PageSize = value
      End Set
    End Property

    Public Property EnableSubjectContact() As Boolean
      Get
        Return _EnableSubjectContact
      End Get
      Set(ByVal value As Boolean)
        _EnableSubjectContact = value
      End Set
    End Property

    Public Property EnableSubjectNotification() As Boolean
      Get
        Return _EnableSubjectNotification
      End Get
      Set(ByVal value As Boolean)
        _EnableSubjectNotification = _EnableSubjectContact And value
      End Set
    End Property

    Public Property EnableNotification() As Boolean
      Get
        Return _EnableNotification
      End Get
      Set(ByVal value As Boolean)
        _EnableNotification = value
      End Set
    End Property

    Public Property TrackVisits() As Boolean
      Get
        Return _TrackVisits
      End Get
      Set(ByVal value As Boolean)
        _TrackVisits = value
      End Set
    End Property

    Public Property TrackViews() As Boolean
      Get
        Return _TrackViews
      End Get
      Set(ByVal value As Boolean)
        _TrackViews = value
      End Set
    End Property

    Public Property TrackNewPosts() As Boolean
      Get
        Return _TrackNewPosts
      End Get
      Set(ByVal value As Boolean)
        _TrackNewPosts = value
      End Set
    End Property

    Public Property EnableDNNSearch() As Boolean
      Get
        Return _EnableDNNSearch
      End Get
      Set(ByVal value As Boolean)
        _EnableDNNSearch = value
      End Set
    End Property

    Public Property UseAdminEmailAsSender() As Boolean
      Get
        Return _UseAdminEmailAsSender
      End Get
      Set(ByVal value As Boolean)
        _UseAdminEmailAsSender = value
      End Set
    End Property

    Public Property AdminEmail() As String
      Get
        Return _AdminEmail
      End Get
      Set(ByVal value As String)
        _AdminEmail = value
      End Set
    End Property

    Public Property MailStyleName() As String
      Get
        Return _MailStyleName
      End Get
      Set(ByVal value As String)
        _MailStyleName = value
      End Set
    End Property

    Public Property MailFormat() As DotNetNuke.Services.Mail.MailFormat
      Get
        Return _MailFormat
      End Get
      Set(ByVal value As DotNetNuke.Services.Mail.MailFormat)
        _MailFormat = value
      End Set
    End Property

    Public Property MailSendMethod() As MailManager.MailSendMethods
      Get
        Return _MailSendMethod
      End Get
      Set(ByVal value As MailManager.MailSendMethods)
        _MailSendMethod = value
      End Set
    End Property

    Public Property EnablePerPortalTemplates() As Boolean
      Get
        Return _EnablePerPortalTemplates
      End Get
      Set(ByVal value As Boolean)
        _EnablePerPortalTemplates = value
      End Set
    End Property

    'The following read only properties return status information stored in ModuleSettings by several
    'stored proceedures in the database

    <XmlIgnore()> _
    Public ReadOnly Property Stats() As Stats
      Get
        If _Stats Is Nothing Then
          Dim epc As New EPrayerController
          _Stats = epc.GetStats(ModuleId)
        End If
        Return _Stats
      End Get
    End Property

    Public ReadOnly Property Requests() As Integer
      Get
        Return Stats.Requests
      End Get
    End Property

    Public ReadOnly Property Updates() As Integer
      Get
        Return Stats.Updates
      End Get
    End Property

    <XmlIgnore()> _
    Public ReadOnly Property MostRecentRequestID() As Integer
      Get
        Return Stats.MostRecentRequestID
      End Get
    End Property

    <XmlIgnore()> _
    Public ReadOnly Property MostRecentPostID() As Integer
      Get
        Return Stats.MostRecentPostID
      End Get
    End Property

    <XmlIgnore()> _
    Public ReadOnly Property MostRecentAuthorID() As Integer
      Get
        Return Stats.MostRecentAuthorID
      End Get
    End Property

    Public ReadOnly Property MostRecentAuthor() As String
      Get
        Return Stats.MostRecentAuthor
      End Get
    End Property

    Public ReadOnly Property MostRecentPostDate() As DateTime
      Get
        Return Stats.MostRecentPostDate
      End Get
    End Property

    Public ReadOnly Property PostsToModerate() As Integer
      Get
        Return Stats.PostsToModerate
      End Get
    End Property
#End Region

#Region "Constructor"
    Public Sub New()
      LoadDefaultSettings()
    End Sub

    Public Sub New(ByVal ModuleConfiguration As Entities.Modules.ModuleInfo, ByVal Settings As Hashtable)
      _ModuleConfiguration = ModuleConfiguration
      With _ModuleConfiguration
        _ModuleId = .ModuleID
        _TabID = .TabID
        _TabModuleID = .TabModuleID
      End With
      _settings = Settings
      LoadSettings()
    End Sub

    Public Sub New(ByVal ModuleId As Integer)
      _ModuleId = ModuleId
      _TabID = CType(HttpContext.Current.Items("PortalSettings"), PortalSettings).ActiveTab.TabID
      Dim mc As New DotNetNuke.Entities.Modules.ModuleController
      _ModuleConfiguration = mc.GetModule(_ModuleId, _TabID)
      _TabModuleID = _ModuleConfiguration.TabModuleID

      Dim tabModuleSettings As Hashtable = mc.GetTabModuleSettings(_TabModuleID)
      Dim moduleSettings As Hashtable = mc.GetModuleSettings(_ModuleId)

      'Merge the TabModuleSettings and ModuleSettings
      _settings = New Hashtable
      For Each strKey As String In tabModuleSettings.Keys
        _settings(strKey) = tabModuleSettings(strKey)
      Next
      For Each strKey As String In moduleSettings.Keys
        _settings(strKey) = moduleSettings(strKey)
      Next
      LoadSettings()
    End Sub

    Public Sub New(ByVal ModuleId As Integer, ByVal Settings As Hashtable)
      _ModuleId = ModuleId
      _TabID = CType(HttpContext.Current.Items("PortalSettings"), PortalSettings).ActiveTab.TabID
      Dim mc As New DotNetNuke.Entities.Modules.ModuleController
      _ModuleConfiguration = mc.GetModule(_ModuleId, _TabID)
      _TabModuleID = _ModuleConfiguration.TabModuleID
      _settings = Settings
      LoadSettings()
    End Sub

#End Region

#Region "Public Methods"
    Public Sub LoadSettings()
      If Not Settings Is Nothing Then
        If Settings.Count = 0 Then
          PreConfigureSettings(ModuleId, TabModuleID)
        Else
          _EnableModeration = GetSetting("EnableModeration", Defaults.EnableModeration)
          _NewUsersAreTrusted = GetSetting("NewUsersAreTrusted", Defaults.NewUsersAreTrusted)
          _NewUsersViewableDistributions = GetSetting("NewUsersViewableDistributions", Defaults.NewUsersViewableDistributions)
          _AnonymousUsersViewableDistributions = GetSetting("AnonymousUsersViewableDistributions", Defaults.AnonymousUsersViewableDistributions)
          _NewPostDefaultDistributions = GetSetting("NewPostDefaultDistributions", Defaults.NewPostDefaultDistributions)
          _AllowOwnPostEditing = GetSetting("AllowOwnPostEditing", Defaults.AllowOwnPostEditing)
          _AllowOwnPostDeletion = GetSetting("AllowOwnPostDeletion", Defaults.AllowOwnPostDeletion)
          _RequestLifespan = GetSetting("RequestLifespan", Defaults.RequestLifespan)
          _MaxBodyLength = GetSetting("MaxBodyLength", Defaults.MaxBodyLength)
          _PageSize = GetSetting("PageSize", Defaults.PageSize)
          _EnableSubjectContact = GetSetting("EnableSubjectContact", Defaults.EnableSubjectContact)
          _EnableSubjectNotification = GetSetting("EnableSubjectNotification", Defaults.EnableSubjectNotification)
          _EnableNotification = GetSetting("EnableNotification", Defaults.EnableNotification)
          _TrackVisits = GetSetting("TrackVisits", Defaults.TrackVisits)
          _TrackViews = GetSetting("TrackViews", Defaults.TrackViews)
          _TrackNewPosts = GetSetting("TrackNewPosts", Defaults.TrackNewPosts)
          _EnableDNNSearch = GetSetting("EnableDNNSearch", Defaults.EnableDNNSearch)
          _UseAdminEmailAsSender = GetSetting("UseAdminEmailAsSender", Defaults.UseAdminEmailAsSender)
          _AdminEmail = GetSetting("AdminEmail", Defaults.AdminEmail)
          _MailStyleName = GetSetting("MailStyleName", Defaults.MailStyleName)
          _MailFormat = GetSetting("MailFormat", Defaults.MailFormat)
          _MailSendMethod = GetSetting("MailSendMethod", Defaults.MailSendMethod)
          Dim hostSettings As Dictionary(Of String, String) = Entities.Host.Host.GetHostSettingsDictionary()
          Dim key As String = ModuleName & "_EnablePerPortalTemplates"
          If hostSettings.ContainsKey(key) Then
            _EnablePerPortalTemplates = Utilities.GetSettingValue(Entities.Host.Host.GetHostSettingsDictionary(ModuleName & "_EnablePerPortalTemplates"), Defaults.EnablePerPortalTemplates)
          Else
            _EnablePerPortalTemplates = Defaults.EnablePerPortalTemplates
          End If
        End If
      End If
    End Sub

    Public Sub SaveSettings()
      SaveSettings(_ModuleId, _TabModuleID)
    End Sub

    Public Sub SaveSettings(ByVal ModuleId As Integer, ByVal TabModuleId As Integer)
      _ModuleId = ModuleId
      _TabModuleID = TabModuleId
      Dim mc As New DotNetNuke.Entities.Modules.ModuleController
      With mc
        .UpdateModuleSetting(ModuleId, "EnableModeration", _EnableModeration.ToString)
        .UpdateModuleSetting(ModuleId, "NewUsersAreTrusted", NewUsersAreTrusted.ToString)
        .UpdateModuleSetting(ModuleId, "NewUsersViewableDistributions", NewUsersViewableDistributions.ToString)
        .UpdateModuleSetting(ModuleId, "AnonymousUsersViewableDistributions", AnonymousUsersViewableDistributions.ToString)
        .UpdateModuleSetting(ModuleId, "NewPostDefaultDistributions", NewPostDefaultDistributions.ToString)
        .UpdateModuleSetting(ModuleId, "AllowOwnPostEditing", _AllowOwnPostEditing.ToString)
        .UpdateModuleSetting(ModuleId, "AllowOwnPostDeletion", _AllowOwnPostDeletion.ToString)
        .UpdateModuleSetting(ModuleId, "RequestLifespan", _RequestLifespan.ToString)
        .UpdateModuleSetting(ModuleId, "MaxBodyLength", _MaxBodyLength.ToString)
        .UpdateModuleSetting(ModuleId, "PageSize", _PageSize.ToString)
        .UpdateModuleSetting(ModuleId, "EnableSubjectContact", _EnableSubjectContact.ToString)
        .UpdateModuleSetting(ModuleId, "EnableSubjectNotification", _EnableSubjectNotification.ToString)
        .UpdateModuleSetting(ModuleId, "EnableNotification", _EnableNotification.ToString)
        .UpdateModuleSetting(ModuleId, "TrackVisits", _TrackVisits.ToString)
        .UpdateModuleSetting(ModuleId, "TrackViews", _TrackViews.ToString)
        .UpdateModuleSetting(ModuleId, "TrackNewPosts", _TrackNewPosts.ToString)
        .UpdateModuleSetting(ModuleId, "EnableDNNSearch", _EnableDNNSearch.ToString)
        .UpdateModuleSetting(ModuleId, "UseAdminEmailAsSender", _UseAdminEmailAsSender.ToString)
        .UpdateModuleSetting(ModuleId, "AdminEmail", _AdminEmail)
        .UpdateModuleSetting(ModuleId, "MailStyleName", _MailStyleName)
        .UpdateModuleSetting(ModuleId, "MailFormat", _MailFormat.ToString)
        .UpdateModuleSetting(ModuleId, "MailSendMethod", _MailSendMethod.ToString)
        Dim hsc As New Entities.Host.HostSettingsController
        hsc.UpdateHostSetting(ModuleName & "_EnablePerPortalTemplates", _EnablePerPortalTemplates.ToString)
      End With
      DataCache.RemoveCache(String.Format(Consts.ConfigurationCacheKey, ModuleId)) 'Invalidate the configuration cache
    End Sub

    Public Sub PreConfigureSettings(ByVal ModuleId As Integer, ByVal TabModuleId As Integer)
      LoadDefaultSettings()
      SaveSettings(ModuleId, TabModuleId)
    End Sub

    Public Sub ReloadStats()
      Stats.Reload()
    End Sub
#End Region

#Region "Private Methods"

    Private Sub LoadDefaultSettings()
      _EnableModeration = Defaults.EnableModeration
      _NewUsersAreTrusted = Defaults.NewUsersAreTrusted
      _NewUsersViewableDistributions = Defaults.NewUsersViewableDistributions
      _AnonymousUsersViewableDistributions = Defaults.AnonymousUsersViewableDistributions
      _NewPostDefaultDistributions = Defaults.NewPostDefaultDistributions
      _AllowOwnPostEditing = Defaults.AllowOwnPostEditing
      _AllowOwnPostDeletion = Defaults.AllowOwnPostDeletion
      _RequestLifespan = Defaults.RequestLifespan
      _MaxBodyLength = Defaults.MaxBodyLength
      _PageSize = Defaults.PageSize
      _EnableSubjectContact = Defaults.EnableSubjectContact
      _EnableSubjectNotification = Defaults.EnableSubjectNotification
      _EnableNotification = Defaults.EnableNotification
      _TrackVisits = Defaults.TrackVisits
      _TrackViews = Defaults.TrackViews
      _TrackNewPosts = Defaults.TrackNewPosts
      _EnableDNNSearch = Defaults.EnableDNNSearch
      _UseAdminEmailAsSender = Defaults.UseAdminEmailAsSender
      _AdminEmail = Defaults.AdminEmail
      _MailStyleName = Defaults.MailStyleName
      _MailFormat = Defaults.MailFormat
      _MailSendMethod = Defaults.MailSendMethod
      _EnablePerPortalTemplates = Defaults.EnablePerPortalTemplates
    End Sub

    Private Function GetSetting(Of T)(ByVal key As String, ByVal defaultValue As T) As T
      Dim obj As Object = Nothing

      If _settings.ContainsKey(key) Then
        obj = _settings(key)
        Return Utilities.GetSettingValue(obj, defaultValue)
      Else
        Return defaultValue
      End If
    End Function
#End Region

  End Class
End Namespace
